from datetime import datetime
from sqlalchemy import Column
from sqlalchemy import DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import String

Base = declarative_base()


def init_db(_ENGINE):
    Base.metadata.create_all(_ENGINE)


class User(Base):
    __tablename__ = 'user'
    id = Column(Integer, primary_key=True)
    name = Column(String(32))
    account = Column(String(32))
    pwd = Column(String(32))
    phone = Column(String(12))
    number = Column(String(19))
    source = Column(String(10), default="platform")
    roleId = Column(Integer, ForeignKey("role.id"))
    status = Column(Integer)
    create_at = Column(DateTime, default=datetime.now)


class Role(Base):
    __tablename__ = 'role'
    id = Column(Integer, primary_key=True)
    title = Column(String(32))
